<script language="javascript" type="text/javascript">
    $(window).scroll(
    function()
    {
        scrollTop = $(window).scrollTop();
        docHeight = getDocHeight();
        winHeight = getWinHeight();
        scrolltop20 = Math.round((getDocHeight() - getWinHeight())*0.9);
        result = getDocHeight() - getWinHeight();
		
        console.log('Top Scroll: '+ scrollTop +' || Win Height: '+ winHeight +' || Doc Height: '+ docHeight+' || scrolltop20: '+scrolltop20+' || result :'+ result );
	
        if($(window).scrollTop() >= scrolltop20)
        {
            if(killScroll == false) 
            {
                killScroll = true;
				
                $('#loading').show();
                $('#loadding-text').show();			
                $('#loading').html('<img src="images/loading.gif" alt="" width="150" height="13" />');
				
                if( $("li:last").data('ctype') == 'market')
                {
                    lastPostFunc('market');
                }				
				
                setTimeout(function(){killScroll = false},500);	
            }
        }
    }
); 
</script>

<!-- Start of market page -->
<div data-role="page" id="market">
    <div data-role="header">
        <h1>ตลาดซื้อ-ขาย</h1>
        <a rel="external" id="link_web" href="?q=home" data-icon="back" data-iconpos="right" data-transition="slide">กลับ</a> 
        <a id="link_market" href="#from_searchMarket" data-icon="search" data-iconpos="right" data-transition="slidedown" data-rel="dialog">ค้นหา</a>        
        <script language="javascript" type="text/javascript">
            function searchMocyc()
            {               
                if($('#product_search').val() != '')
                {						
                    $('#fromSearchMarket').submit();
                }
                else
                {
                    $('#popupBasic').popup('open');
                    setTimeout(function(){$('#popupBasic').popup('close'); $('#product_search').focus()},1000);
                }
            }
        
        </script>  
    </div><!-- /header -->
    <div data-role="content" id="market_list">
        <ul data-role="listview">
            <li data-role="list-divider" id="listDivider_step">
                <a rel="external" href="?q=home">หน้าแรก</a>&nbsp;&nbsp;>>&nbsp;&nbsp;<a rel="external" href="?q=market">ตลาด</a>
            </li>      
            <?php
            $res = $db->select_query('SELECT * FROM products ORDER BY id DESC LIMIT 20');
            while($arr = $db->fetch($res))
            {
                $countReply = $db->num_rows('product_reply', 'reply_id', 'product_id = ' . $arr['id'] . '');
                ?>
                <li data-ctype="market" id="market_<?php echo $arr['id']; ?>" last_id="<?php echo $arr['id']; ?>">
                    <a rel="external" href="?q=productDetail&pid=<?php echo $arr['id']; ?>">
                        <img src="<?php echo $arr['tn_part']; ?>" alt="" width="80" height="80" />
                        <h3><?php echo $arr['name']; ?></h3>
                        <p><?php echo $arr['headline']; ?></p>
                        <span class="ui-li-count ui-btn-up-c ui-btn-corner-all"><?php echo $countReply; ?></span>
                    </a> 
                </li>
                <?php
            }
            ?>
        </ul>  
        <div id="loadding-text" style="clear:both;" align="center">&nbsp;</div>        
        <div id="loading" align="center"></div>   
    </div><!-- /content -->
    <div data-role="footer" >
        <h4>Version 1.0 Beta</h4>
        <a id="link_web" href="http://www.mocyc.com" data-icon="refresh" data-iconpos="right" class="ui-btn-right">แบบปกติ</a>
    </div><!-- /footer -->
</div>

<!-- Market page -> From MarketSearch -->
<div data-role="page" id="from_searchMarket">
    <div data-role="header">
        <h1>ค้นหา</h1>
    </div>
    <div data-role="content">
        <form id="fromSearchMarket" name="fromSearchMarket" method="get" data-transition="slide" data-ajax="false">
            <input name="q" type="hidden" value="marketSearch" />
            คำค้นหา
            <input  type="search" name="product_search" id="product_search" value=""  />    
            สภาพ
            <select name="product_status" id="product_status">
                <option value="0" selected="selected">- ไม่ระบุ -</option>
                <option value="1">สินค้าใหม่</option>
                <option value="2">สินค้ามือสอง</option>
                <option value="3">สินค้าอื่นๆ</option>
            </select>
            หมวดหมู่
            <select name="category" id="category">
                <option value="0" selected="selected">- ไม่ระบุ -</option>
                <option value="1">มอเตอร์ไซค์</option>
            </select>

            ยี้ห้อ
            <select name="trade" id="trade">
                <option value="0" selected="selected">- ไม่ระบุ -</option>
                <option value="1">Ace</option>
                <option value="2">Acme</option>
            </select>

            จังหวัด
            <select name="province" id="province">
                <option value="0" selected="selected">- ไม่ระบุ -</option>
                <?php
// localhost  » mobile  » province // PROVINCE_ID 	PROVINCE_CODE 	PROVINCE_NAME 	PROVINCE_NAME_ENG 	GEO_ID 
                $res = $db->select_query('SELECT PROVINCE_ID, PROVINCE_NAME FROM province ORDER BY PROVINCE_NAME ASC');
                while($arr = $db->fetch($res))
                {
                    ?>
                    <option value="<?php echo $arr['PROVINCE_ID']; ?>"><?php echo $arr['PROVINCE_NAME']; ?></option>
                    <?php
                }
                ?>
            </select>
            <label>&nbsp;</label><br /> 
            <input id="search" name="search" type="button" value="ค้นหา" onclick="searchMocyc();" />
        </form>
        <div data-role="popup" id="popupBasic">
            <p>กรุณาระบุ "คำค้นหา" ที่ต้องการ<p>
        </div>        
    </div>
</div>
<!-- End Market page From MarketSearch -->